//1. 安装  npm i redux
//2. 新建文件  src/redux/store.js
//3. 导入『创建状态仓库』的函数 createStore create 创建  store 仓库, 存储
import { composeWithDevTools } from 'redux-devtools-extension';
import {createStore, applyMiddleware, combineReducers} from 'redux';
import thunk from 'redux-thunk';
import CollReducer from './reducers/CollReducer';
import CommentReducer from './reducers/CommentReducer';

//合并 reducer 函数
let reducer = combineReducers({
    coll: CollReducer,
    comment: CommentReducer
});


//4. 调用函数, 创建状态仓库  action 是一个对象, 两个属性: type 操作类型  data 操作使用的数据
const store = createStore(reducer, composeWithDevTools(applyMiddleware(thunk)));

//异步修改状态 
// store.dispatch((dispatch) => {
//     setTimeout(() => {
//         dispatch({type: 'COLL_ADD', data: 5})
//     }, 2000)
// })

//6. 暴露 store 对象
export default store;